const express = require("express");
const router = express.Router();
const db = require("../db/index");
router.post("/save", function (req, res) {
  const { day, mobiles } = req.body;
  var day_money = db.day_money.get("day_money").value();
  day_money[day] = mobiles;
  db.day_money.set("day_money", day_money).write();
  return res.json({
    code: 0,
    data: [],
  });
});
router.get("/get", function (req, res) {
  const query = req.query;
  let dbData = db.day_money.get("day_money").value() || [];
  let data = [];
  Object.keys(dbData).forEach((item) => {
    data.push({
      day: item,
      mobiles: dbData[item],
    });
  });
  if (query.day) {
    data = data.filter((item) => item.day === query.day);
  }
  return res.json({
    code: 0,
    data,
  });
});
module.exports = router;
